#########################
#   Author : Leon yu    #
#   Date : 2025/06/03   #
#   Id : SM2772         #
#########################
from bussinessApis import orgId, businessEnv
from bussinessApis.apiResp import *
from dbResps import storeId, timestamp2Data

apiResps = ApiResps(env=businessEnv, orgId=orgId)

# 数据解析

# 营业概览
def analyzeQueryBusinessTrendReport(businessType:str, startTime:int, endTime:int, storeId:str=storeId):
    queryBusinessTrendReportResp = apiResps.queryBusinessTrendReportResp(storeId=storeId, businessType=businessType, startTime=startTime, endTime=endTime)
    data = queryBusinessTrendReportResp['data']['trendDatas']
    data = [{i['xValue']:i['yValue']} for i in data]
    return data
    
# 订单列表
def analyzeQueryOrderListResp(startTime, endTime, status:str="", pageNum:int=1, pageSize:int=1000, subPlatform=[], storeId:str=storeId):
    queryOrderListResp = apiResps.queryOrderListResp(storeId=storeId, startTime=startTime, endTime=endTime, status=status, pageNum=pageNum, pageSize=pageSize, subPlatform=subPlatform)
    data = queryOrderListResp['data']['list']
    data = [i for i in data if i['status']=="SETTLED"]
    return data[0]

# 销售统计
def analyzeQueryStoreSalesReport(startTime, endTime, pageNum:int=1, pageSize:int=1000, platform=None, storeId:str=storeId):
    queryStoreSalesReportResp = apiResps.queryStoreSalesReportResp(storeId=storeId, startTime=startTime, endTime=endTime, pageNum=pageNum, pageSize=pageSize, platform=platform)
    data = queryStoreSalesReportResp['data']
    return data

# 销售明细
def analyzeQuerySalesItemReport(startTime:int, endTime:int, pageNum:int=1, pageSize:int=1000, categoryName="", storeId:str=storeId):
    queryStoreSalesReportResp = apiResps.querySalesItemReportResp(storeId=storeId, startTime=startTime, endTime=endTime, pageNum=pageNum, pageSize=pageSize, categoryName=categoryName)
    data = queryStoreSalesReportResp['data']
    return data

# 折扣明细
def analyzeQueryDiscountDetailReport(startTime, endTime, pageNum:int=1, pageSize:int=1000, userId="", storeId:str=storeId):
    queryStoreSalesReportResp = apiResps.queryDiscountDetailReportResp(storeId=storeId, startTime=startTime, endTime=endTime, pageNum=pageNum, pageSize=pageSize, userId=userId)
    data = queryStoreSalesReportResp['data']['list']
    return data

# 税目明细
def analyzeQueryTaxIncomeReport(startTime:int, endTime:int, pageNum:int=1, pageSize:int=1000, storeId=storeId):
    queryStoreSalesReportResp = apiResps.queryTaxIncomeReportResp(storeId=storeId, startTime=startTime, endTime=endTime, pageNum=pageNum, pageSize=pageSize)
    data = queryStoreSalesReportResp['data']
    return data

# 税目明细-税目名称 queryTaxDetailReport
def analyzeQueryTaxDetailReport(startTime:int, endTime:int, pageNum:int=1, pageSize:int=1000, storeId=storeId):
    queryStoreSalesReportResp = apiResps.queryTaxDetailReportResp(storeId=storeId, startTime=startTime, endTime=endTime, pageNum=pageNum, pageSize=pageSize)
    data = queryStoreSalesReportResp['data']
    return data

# 储值报表
def analyzeEMemberBalanceReport(startTime:int, endTime:int, pageNum:int=1, pageSize:int=1000, staffId="", searchText="", storeId=storeId):
    eMemberBalanceReportResp = apiResps.eMemberBalanceReportResp(storeId=storeId, startTime=startTime, endTime=endTime, pageNum=pageNum, pageSize=pageSize, staffId=staffId, searchText=searchText)
    data = eMemberBalanceReportResp['data']
    return data

# 员工绩效
def analyzeQueryEmployPerformanceReport(startTime:int, endTime:int, pageNum:int=1, pageSize:int=1000, employeeId="", storeId=storeId):
    queryEmployPerformanceResp = apiResps.queryEmployPerformanceReportResp(storeId=storeId, startTime=startTime, endTime=endTime, pageNum=pageNum, pageSize=pageSize, employeeId=employeeId)
    data = queryEmployPerformanceResp['data']
    return data

 # 新营业概览-营业
def analyzeEBusinessReport(startTime:int, endTime:int, platform=None, storeId=storeId):
    eBusinessReportResp = apiResps.eBusinessReportResp(storeId=storeId, startTime=startTime, endTime=endTime, platform=platform)
    data = eBusinessReportResp['data']
    return data

# 新营业概览-收款
def analyzeEAccountingItemsReport(startTime:int, endTime:int, platform=None, storeId=storeId):
    eAccountingItemsReportResp = apiResps.eAccountingItemsReportResp(storeId=storeId, startTime=startTime, endTime=endTime, platform=platform)
    data = eAccountingItemsReportResp['data']
    return data

# 新营业概览-菜品
def analyzeQueryDishesReport(startTime:int, endTime:int, platform=None, storeId=storeId):
    queryDishesReportResp = apiResps.queryDishesReportResp(storeId=storeId, startTime=startTime, endTime=endTime, platform=platform)
    data = queryDishesReportResp['data']
    return data